package x.ovo.wechat.bot.common.command;

import lombok.Data;
import lombok.RequiredArgsConstructor;

import java.util.Arrays;

/**
 * 命令
 *
 * @author ovo, created by 2024/05/02
 */
@Data
@RequiredArgsConstructor
public class Command {

    private final String command;
    private final String fromName;

    /**
     * 取得指令执行的子参数
     * <p>
     * 例如对于 test ag1 ag2 得到[ag1,ag2]元素
     *
     * @return {@link String[] }
     */
    public String[] formatArgs() {
        return Arrays.stream(command.split(" "))
                .skip(1)
                .toArray(String[]::new);
    }

    /**
     * 获取 main 命令
     *
     * @return {@link String }
     */
    public String getMainCommand() {
        if (!command.contains(" ")) return command;
        return command.substring(0, command.indexOf(" "));
    }

}
